package com.kfm.jdbc.day0328;


import java.lang.reflect.Field;
import java.util.Arrays;

public class Demo {

    public static void main(String[] args) {
        Class<Student> studentClass = Student.class;

        // 字段
        Field[] fields = studentClass.getFields();
        System.out.println(Arrays.toString(fields));

        Field[] declaredFields = studentClass.getDeclaredFields();
        System.out.println(Arrays.toString(declaredFields));

        // 获取指定属性
        try {
            Student student = studentClass.newInstance();
            Field name = studentClass.getDeclaredField("name");

            name.setAccessible(true);

            // student.name = "西安"
            name.set(student, "西安");

            // student.address
            name.get(student);

            System.out.println(student);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }

    }
}
